import { Tools } from 'weaver-mobile';

export default modName => {
  return (actName, settings = {}) => new Promise((res, rej) => {
    Tools.callApi({
      url: `/api/${modName}/${actName}`,
      ...settings
    }).then(result => {
      if (!result.hasOwnProperty('api_status')) return res(result);

      const { api_status } = result;

      if (api_status) {
        res(result.data);
      } else {
        rej(result.api_errormsg);
      }
    });
  });
}